jQuery(document).ready(function ($) {
    var student_show_num = [];
    draw(student_show_num, "studentVcodeimage");
    $("#studentVcodeimage").on('click',function(){
        draw(student_show_num, "studentVcodeimage");
    })

	$('#studentform').submit(function (event) {
		event.preventDefault();
        var vcode = $("#studentVcode").val().toLowerCase();
        var num = student_show_num.join("");
        if (vcode == num) {
            $("#studentVcode").val('');
            draw(student_show_num, "studentVcodeimage");

            var data = 'username=' + $('#studentID').val() + '&password=' + $('#studentName').val() + "&from=student";
            $.ajax({
                data: data,
                timeout: 1000,
                type: 'POST',
                url: 'login'

            }).done(function(data, textStatus, jqXHR) {
                var cookie = JSON.stringify({studentID: $('#studentID').val(),studentName: $('#studentName').val()});
                $.cookie('bjou_student', cookie);
                window.location = "student/index.html";
            }).fail(function(jqXHR, textStatus, errorThrown) {
                layer.open({
                            type: 1
                            ,offset: 'auto'
                            ,content: '<div style="padding: 20px 100px;">您输入的学号或姓名有误</div>'
                            ,btn: '关闭全部'
                            ,btnAlign: 'c' //按钮居中
                            ,shade: 0 //不显示遮罩
                            ,yes: function(){
                              layer.closeAll();
                            }
                          });
            });
        } else {
            layer.open({
                type: 1
                ,offset: 'auto'
                ,content: '<div style="padding: 20px 100px;">验证码输入错误！</div>'
                ,btn: '关闭全部'
                ,btnAlign: 'c' //按钮居中
                ,shade: 0 //不显示遮罩
                ,yes: function() {
                    layer.closeAll();
                }
            });
            $("#studentVcode").val('');
            draw(student_show_num);
        }
	});

	$('#schoolTab').on("click", function(){
	    window.location = "schoolIndex.html";
	});
});


layui.use('layer', function(){ //独立版的layer无需执行这一句
	var layer = layui.layer;
});

